Feature: 圈子
  作为一个律团律师用户
  我可以通过组建圈子和其他律师进行交互


# 不成功

Scenario: 只有律师用户才可以创建圈子，不是的话则报403错误
Given a normal user "1" exists with:
    | username    | password   |
    | 13702321155 | 123456   |
    And http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702321155 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I make a "post" request to "group/store" with:
        |  group_name  |
        |        |
    And the response is in "json" format
    Then the response status code should be 403
    And I see error message "你没有权限访问这个接口，因为你不是律师." for field "message"
    And the response is in "json" format

Scenario: 创建圈子的时候如果圈子名字超过15个字则报400错误
Given http "accept" header is "application/json"
And I make a "post" request to "login" with:
    | username    | password   |
    | 13902310360 | 123456   |
And the response is in "json" format
And http "accept" header is "application/json"
And http "authorization" header exists
And I make a "post" request to "group/store" with:
    |  group_name  |
    |  测试一个很长的圈子名字看看行不行         |           # 16个字
And the response is in "json" format
Then the response status code should be 400
And I got error message "群的名字不能超过15个字" for field "group_name"
And I make a "post" request to "group/store" with:
    |  group_name  |
    |  测试一个很长的圈子名字看行不行         |            # 15个字
And the response is in "json" format
Then the response status code should be 400
And I can not see error message "群的名字不能超过15个字" for field "group_name"



Scenario: 创建圈子的时候如果圈子名字为空则报400错误
Given http "accept" header is "application/json"
And I make a "post" request to "login" with:
    | username    | password   |
    | 13902310360 | 123456   |
And the response is in "json" format
And http "accept" header is "application/json"
And http "authorization" header exists
And I make a "post" request to "group/store" with:
    |  members  |
    |           |
And the response is in "json" format
Then the response status code should be 400
And I got error message "请输入群名" for field "group_name"
And I got error message "请输入群头像" for field "group_avatar"

Scenario: 创建圈子的时候如果圈子名字已经被使用了则报400错误
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I make a "post" request to "group/store" with:
        | group_name    | group_avatar   |  members[0]  |
        |     刑事辩护律团网                    |                         |               |
    And the response is in "json" format
    Then the response status code should be 400
    And I got error message "该群名已被使用" for field "group_name"

Scenario: 只有圈子的创建人可以设置圈子，如果不是的话会报401错误(POST /group/{groupId}/edit)
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325513 | 123456   |
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325513 | 123456   |
    And http "authorization" header exists
    And I make a "post" request to "/group/3/edit" with:
         | group_name    | group_avatar |
        |            |                       |
    Then the response status code should be 401
    And the response is in "json" format
    And I see error message "您没有权限设置该圈子" for field "message"

Scenario: 设置圈子的时候，如果圈子的名字变了，而且这个名字已被其他的圈子使用，则会报400错误(POST /group/{groupId}/edit)
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And http "authorization" header exists
    And I make a "post" request to "group/3/edit" with:
        | group_name    | group_avatar   |  members[0]  |
        |     刑事辩护律团网     |                         |               |
    And print last response
    And the response is in "json" format
    Then the response status code should be 400
    And I got error message "该名已被使用" for field "group_name"

Scenario: 只有管理员才可以添加成员，如果不是的话会报401错误(POST /group/{groupId}/addmember)
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325515 | 123456   |
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325515 | 123456   |
    And http "authorization" header exists
    And I make a "post" request to "group/3/addmember" 
    And print last response
    And the response is in "json" format
    Then the response status code should be 401
    And I see error message "只有管理员才可以添加成员" for field "message"

Scenario: 只有管理员才可以删除成员，如果不是的话会报401错误(GET /group/{groupId}/removemember/{userId})
Given http "accept" header is "application/json"
And http "authorization" header exists
     And a lawyer exists with:
        | username    | password   |
        | 13702325513 | 123456   |
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325513 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/3/removemember/1501"
    And the response is in "json" format
    Then the response status code should be 401
    And I see error message "只有管理员才可以删除成员" for field "message"

Scenario: 加入圈子的时候，如果已经是圈子的成员，则会报400错误(POST /group/{groupId}/join)（函数有问题）
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325514 | 123456   |
    And this lawyer is a member of group "3"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325514 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I make a "post" request to "group/3/join"
    And the response is in "json" format
    Then the response status code should be 400
    And I see error message "你已经是该圈子成员" for field "error_messages"

Scenario: 离开圈子的时候，如果不是圈子的成员，则会报400错误（GET /group/{groupId}/quit）
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325517 | 123456   |
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325517 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And this lawyer is not a member of group "3"
    And I am on "/group/3/quit"
    And the response is in "json" format
    Then the response status code should be 400
    And I see error message "你不是该圈子成员" for field "error_messages"

Scenario: 如果圈子的创建人离开圈子，则会报401错误，创建人只能解散圈子( GET /group/{groupId}/dissolution)
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/3/quit"
    And the response is in "json" format
    Then the response status code should be 401
    And I see error message "创建人只能解散该圈子" for field "message"

Scenario: 删除圈子成员的时候，如果成员是圈子的创建人，则会报401错误
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/3/removemember/3"
    And the response is in "json" format
    Then the response status code should be 401
    And I see error message "不能删除这个成员，因为他是圈子的创建者" for field "message"

Scenario: 解散圈子的时候，如果用户不是圈子的创建人，则会报401错误
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325517 | 123456   |
    And the response is in "json" format
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325517 | 123456   |
    And http "authorization" header exists
    And I am on "/group/3/dissolution"
    And the response is in "json" format
    Then the response status code should be 401
    And I see error message "您没有权限解散该圈子" for field "message"

# 成功

Scenario: 创建圈子 /group/create （创建者自动关注该圈子，并成为管理员）
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I make a "post" request to "group/store" with:
        | group_name    | group_avatar            | members[0] |
        | random_str    | img/succreturn-logo.png |    2    |
    And the response is in "json" format
    Then the response status code should be 200
    And I see elements in the response with values:
    | member_cnt |
    | 2          |
    
Scenario: 获取被推荐的圈子的列表 /group/recommend
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/recommend"
    Then the response status code should be 200
    And the response is in "json" format
    And I see elements in the response:
    | id |
   
Scenario: 获取我的圈子列表 /group/list/mine
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/list/mine"
    Then the response status code should be 200
    And the response is in "json" format
    And print last response
    And I see elements in the response:
    | id |

Scenario: 获取一个圈子的详情 /group/{groupId}/detail
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/3/detail"
    Then the response status code should be 200
    And the response is in "json" format
    And I see message "3" for field "id"

Scenario: 设置一个圈子 /group/{groupId}/edit
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I make a "post" request to "group/3/edit" with:
        | group_name    | group_avatar   |
        |      刑事辩护律团网sss                   |         ddd                | 
    Then the response status code should be 200
    And the response is in "json" format
    And I see message "刑事辩护律团网sss" for field "group_name"

Scenario: 添加圈子成员 /group/{groupId}/addMember（POST /group/{groupId}/addmember）（如何获取新创建的律师的id）
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
     And a lawyer exists with:
        | username    | password   |
        | 13702325513 | 123456   |
    And I make a "post" request to "group/87/addmember" with:
    | members[0] |
    | lawyer  |
    Then the response status code should be 200
    And the response is in "json" format
    And print last response

Scenario: 删除圈子成员 /group/{groupId}/removeMember （ GET /group/{groupId}/removemember/{userId}）（要确保圈子中有该成员）
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And a lawyer exists with:
        | username    | password   |
        | 13702325521 | 123456   |
    And this lawyer is a member of group "87"
    And http "authorization" header exists
    And I am on "/group/87/removemember/1501"
    Then the response status code should be 200
    And the response is in "json" format
    And I see error message "删除成功" for field "data"

Scenario: 关注一个圈子 /group/{groupId}/join
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325513 | 123456   |
    And this lawyer is not a member of group "3"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325513 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I make a "post" request to "group/3/join"
    Then the response status code should be 200
    And the response is in "json" format
    And I see error message "加入成功" for field "data"

Scenario: 离开一个圈子 /group/{groupId}/quit
Given http "accept" header is "application/json"
    And a lawyer exists with:
        | username    | password   |
        | 13702325516 | 123456   |
    And the response is in "json" format
    And this lawyer is a member of group "3"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13702325516 | 123456   |
    And http "authorization" header exists
    And I am on "/group/3/quit"
    Then the response status code should be 200
    And the response is in "json" format
    And I see error message "退出成功" for field "data"

Scenario: 解散一个圈子 /group/{groupId}/dissolution
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/87/dissolution"
    Then the response status code should be 200
    And the response is in "json" format
    And I see error message "成功解散圈子。" for field "data"

Scenario: 圈子的内页显示登录用户是否群主和管理员 /group/{groupId}/chat
Given http "accept" header is "application/json"
    And I make a "post" request to "login" with:
        | username    | password   |
        | 13902310360 | 123456   |
    And the response is in "json" format
    And http "authorization" header exists
    And I am on "/group/3/chat"
    Then the response status code should be 200
    And the response is in "json" format
    And I see elements in the response with values:
    | is_admin | is_creator |
    | true     | true       |
    
Scenario: 圈子内页（要讨论如何测试） /group/{groupId}/chat